<?php
namespace Home\Common;
use Common\Common\Common;
	//Home\Common\DbOperation;
class Data
{
	public $data;
	public $table = "products";
	function __construct()
	{}

	function add($PackageCode, $Period)
	{
		do {
            $ProductId = Common::uuid();
            $check_value['productid'] = $ProductId;
        } while (DbOperation::check_exist($this->table, $check_value));
        //构建数据
        $data['productid'] = $ProductId;
        $data['packagecode'] = $PackageCode;
        $data['createtime'] = time();
        $data['expiretime'] = strtotime("+".$Period." month");
        $data['nsgroupcount'] = 0;
        $data['domaincount'] = 0;
        $data['status'] = 'enabled';
        $data['deleted'] = 'N';
        $data['deletetime'] = '';

		return returnAction(DbOperation::add($this->table, $data));
	}

	function info($ProductId, $Deleted='N', $table='products')
	{      
        $check_value['productid'] = $ProductId;
        $check_value['deleted'] = $Deleted;
		return returnAction(DbOperation::read($table, $check_value));
	}

	function update($ProductId, $data)
	{
		$conditions['productid'] = $ProductId;
		return returnAction(DbOperation::update($this->table, $conditions, $data));
	}

	function period($ProductId, $Period)
	{
		$data = DbOperation::read($table, $check_value);//获取原来的过期时间
        $OldExpireTime = $data[0]['expiretime'];

        $ExpireTime = strtotime("+".$Period." month",$OldExpireTime);//修改过期时间
        $data['expiretime'] = $ExpireTime;
		return returnAction($this->update($ProductId, $data));
	}

	function delete($ProductId)
	{
        $data['deleted'] = 'Y';
        $data['deletetime'] = time();
        return returnAction($this->update($ProductId, $data));
	}

	// function isExist($ProductId)
	// {
	// 	$check_value['productid'] = $ProductId;
 //        $check_value['deleted'] = 'N';

	// 	return returnAction(DbOperation::check_exist($table, $check_value));
	// }

	// function isDeleted($ProductId)
	// {
	// 	$check_value['productid'] = $ProductId;
 //        $check_value['deleted'] = 'Y';

	// 	return returnAction(DbOperation::check_exist($table, $check_value));
	// }	function exist($ProductId)
	// {
	// 	$check_value['productid'] = $ProductId;
 //        $check_value['deleted'] = 'N';

	// 	return returnAction(DbOperation::check_exist($table, $check_value));
	// }

	// function revoke($ProductId)
	// {
 //        $data['deleted'] = 'N';
 //        $data['deletetime'] = NULL;
 //        return $this->update($ProductId, $data);
	// }

	// function addNS($ProductId)
	// {
	// 	$data = $this->info($Product);
	// 	$data['nsgroupcount'] = $data[0]['nsgroupcount'] + 1;//修改NS组数量
	// 	return $this->update($ProductId, $data);
	// }
}
